import React from 'react';
import {inject, observer} from 'mobx-react';

import PersonTree from '../../../public/persontree/PersonTree';

@inject ('planResultListStore')
@observer
export default class LeftCom extends React.Component {
  constructor (props) {
    super (props);
    this.state = {};
    this.store = this.props.planResultListStore;
  }

  onNodeSelect = (e, ids, selectedKeys, nodes) => {
    this.store.resetMoreSearch ();
    if (selectedKeys && selectedKeys.length > 0) {
      let type = parseInt (selectedKeys[0].split ('__')[0]) + 1;
      let id = selectedKeys[0].split ('__')[1];

      switch (type) {
        case 4:
          let hrmIds = [];
          hrmIds.push (id);
          this.store.moreSearchValues.hrmIds = hrmIds;
          break;
        case 3:
          this.store.moreSearchValues.dep = id;
          break;
        case 2:
          this.store.moreSearchValues.sub = id;
          break;
      }
      this.store.getResultListTable ();
    }
  };

  onPersonClick = (hrmId, hrmName) => {
    this.store.moreSearchValues['hrmIds'] = hrmId;
    this.store.moreSearchValues['hrmnames'] = hrmName;
    this.store.getResultListTable ();
  };
  render () {
    return (
      <PersonTree ecId={`${this && this.props && this.props.ecId || ''}_PersonTree@am3mm0`}
        onPersonClick={this.onPersonClick}
        treeNodeClick={this.onNodeSelect}
      />
    );
    // return <div></div>
  }
}
